package hotel.action;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import hotel.service.IHotelPicService;
import common.action.BaseAction;
import common.pojo.HotelPic;
import common.utils.Page;
import common.utils.PageUtil;
import common.utils.PaginationUtil;
import static common.utils.Constants.*;

@Scope("prototype")
@Controller("hotelPicAction")
public class HotelPicAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	
	public String getHotelPicListByPage() throws Exception {
		String currentTmp = request.getParameter("current");
		String where="";
		int total=hotelPicService.getCount(where);
		int current=PageUtil.getCurrent(currentTmp);
		Page page = PageUtil.createPage(LIMIT, total, current);
		hotelPicList = hotelPicService.find(where,page.getBeginIndex(), LIMIT, "sort desc,id desc");
		pagination = PaginationUtil.getPaginationStyleTwo(page,
				"getHotelPicListByPage.action");	
		return "hotelPicListByPage";
	}
	
	public String save(){
		hotelPicService.save(hotelPic);
		return "success2";
	}

	public String findInfoById(){
		int id= Integer.valueOf(request.getParameter("id"));
		hotelPic=hotelPicService.find(id);
		return "findSuccess";
	}

	public String update(){
		hotelPicService.update(hotelPic);
		return "success2";
	}
	
	public String delete(){
		String ids=request.getParameter("ids");
		hotelPicService.delete(ids);
		return SUCCESS;
	}

	public String sort() throws IOException {
		String[] ids=request.getParameterValues("id");
		String[] sorts=request.getParameterValues("sort");
		hotelPicService.update(ids,sorts);
		return SUCCESS;
	}
	
	@Resource
	private IHotelPicService hotelPicService;
	private List<HotelPic> hotelPicList;
	private String pagination;
	private HotelPic hotelPic;
	private String dofunction="()";

	

	public String getDofunction() {
		return dofunction;
	}

	public void setDofunction(String dofunction) {
		this.dofunction = dofunction;
	}

	public String getPagination() {
		return pagination;
	}

	public void setPagination(String pagination) {
		this.pagination = pagination;
	}
	public List<HotelPic> getHotelPicList() {
		return hotelPicList;
	}
	public void setHotelPicList(List<HotelPic> hotelPicList) {
		this.hotelPicList = hotelPicList;
	}
	public HotelPic getHotelPic() {
		return hotelPic;
	}
	public void setHotelPic(HotelPic hotelPic) {
		this.hotelPic = hotelPic;
	}

}
